package com.stx.jeepay.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.stx.jeepay.core.dao.MchNotifyRecordDao;
import com.stx.jeepay.core.entity.MchNotifyRecordEntity;
import com.stx.jeepay.core.service.MchNotifyRecordService;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("mchNotifyRecordService")
public class MchNotifyRecordServiceImpl extends ServiceImpl<MchNotifyRecordDao, MchNotifyRecordEntity> implements MchNotifyRecordService {


    /**
     * 查询支付订单
     */
    @Override
    public MchNotifyRecordEntity findByPayOrder(String orderId) {
        return findByOrderAndType(orderId, MchNotifyRecordEntity.TYPE_PAY_ORDER);
    }

    /**
     * 修改通知结果
     */
    @Override
    public Integer updateNotifyResult(Long notifyId, Byte state, String resResult) {
        return baseMapper.updateNotifyResult(notifyId, state, resResult);
    }

    /**
     * 查询退款订单订单
     */
    @Override
    public MchNotifyRecordEntity findByRefundOrder(String orderId) {
        return findByOrderAndType(orderId, MchNotifyRecordEntity.TYPE_REFUND_ORDER);
    }

    /**
     * 查询退款订单订单
     */
    @Override
    public MchNotifyRecordEntity findByTransferOrder(String transferId) {
        return findByOrderAndType(transferId, MchNotifyRecordEntity.TYPE_TRANSFER_ORDER);
    }

    /**
     * 根据订单号和类型查询
     */
    public MchNotifyRecordEntity findByOrderAndType(String orderId, Byte orderType) {
        return getOne(new LambdaQueryWrapper<MchNotifyRecordEntity>()
                .eq(MchNotifyRecordEntity::getOrderId, orderId)
                .eq(MchNotifyRecordEntity::getOrderType, orderType));
    }
}